package Arrays;

public class _238_ProductofArrayExceptSelf {
    //think about when nums has several 0
    public int[] productExceptSelf(int[] nums) {
        int product = 1;
        int count = 0;
        int output[] = new int[nums.length];
        for (int i : nums) {
            if (i != 0) {
                product *= i;
            } else {
                count++;
            }
        }
        if (count==0) {
            for(int i=0;i<output.length;i++) {
                output[i] = product/nums[i];
            }
        }else if (count==1) {
            for(int i=0;i<output.length;i++) {
                if (nums[i] != 0) {
                    output[i] = 0;
                } else {
                    output[i] = product;
                }
            }
        } else {
            return output;
        }
        return output;
    }
}
